package com.sunny.ynhz.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by luao on 2017/5/25.
 */

public class DashView extends View {

    private Paint paint;
    private int x;
    private int y;
    private int count = 1000;
    private int radius;
    private int juli;
    private int circleX;
    private int circleY;
    private String colorString = "#00FFFF";

    public DashView(Context context) {
        super(context);
    }

    public DashView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DashView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DashView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        x = MeasureSpec.getSize(widthMeasureSpec);
        y = MeasureSpec.getSize(heightMeasureSpec);

        init();
    }


    private void init() {

        paint = new Paint();
//        paint.setStrokeWidth(circleWidth);
//        paint.setStyle(Paint.Style.STROKE);
        paint.setAntiAlias(true);
//        progressPaint.setShadowLayer(30,10,0,Color.parseColor("#FF0000"));
        paint.setColor(Color.parseColor(colorString));

        juli = 3*x;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        radius = Math.min(x, y);
        for (int i = 0; i < count; i++) {
            circleX = radius / 2;//圆心的X

            circleY = radius / 2 + (radius + juli) * i;//圆心的Y

            canvas.drawCircle(circleX, circleY, radius / 2, paint);// 小圆
        }


    }


}
